@extends('Layouts.layout')
@section('title','登录')
@section('content')
    <form action="" name="frm" method="post" class="url" data-url="{{ url($perfix.'/login') }}">
    <div class="login">
        <div class="banner">
            <img src="/business/images/ren.png" alt="">
        </div>
            <div class="content">
                <div class="form required shadow">
                    <ul>
                        <li class="phone">
                            <i class="i"></i>
                            <input type="number" placeholder="手机号" name="phone"  value="{{ old('phone') }}" oninput="if(value.length>11)value=value.slice(0,11)">
                            <i class="clear_ none"></i>
                        </li>
                        <li class="pwd">
                            <i class="i"></i>
                            <input type="password" placeholder="密码" name="password" value="" maxlength="20">
                            <i class="clear_ none"></i>
                            <i class="pwd_visible" onclick="pwdVisible(this)"></i>
                        </li>
                        <li class="border_none">
                            <a href="{{ url($perfix.'/forgot') }}">忘记密码 ?</a>
                        </li>
                    </ul>
                    <p class="btn_" onclick="checkLogin(this)">登录</p>
                </div>
                            <div class="goLogin">没有账号<a href="{{url($perfix.'/register')}}">去注册</a></div>
            </div>
    </div>
    </form>
    <script>
        function checkLogin(obj){
            if($(obj).hasClass('on')) {
                if (!mobile.test($('.phone input').val())) {
                    errorMsg('电话号码不正确');
                    return false;
                } else if (!pass.test($('.pwd input').val())) {
                    errorMsg('请输入6-20位数字和字母组成的密码')
                    return false;
                } else {
                    var url = $(".url").data('url');
                    $.ajax({
                        url: url,
                        type: 'post',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        data: {
                            '_token': $('meta[name="csrf-token"]').attr('content'),
                            phone: $('.phone input').val(),
                            password: $('.pwd input').val()
                        },
                        success: function (data) {
                            if (data.code > 0) {
                                layer.open({
                                    content: data.message,
                                    skin: 'msg',
                                    time: 2
                                })
                            } else {
                                window.location.href = '/product';
                            }
                        },
                        error: function () {
                            layer.open({
                                content: '请求错误',
                                skin: 'msg',
                                time: 2
                            })
                        }
                    });
                }
            }
        }
    </script>

@endsection
